package com.elegantsoft.pakistannews;

import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.atiffarrukh.pakistannews.R;
import com.google.analytics.tracking.android.EasyTracker;
import com.tjeannin.apprate.AppRate;

public class EnglishUrduChoice extends SherlockActivity {

	Button eng, ur;
	boolean english, mainAct;
	Intent i;
	SharedPreferences prefs;
	private int lunchCount;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.english_urdu);
		
		AlertDialog.Builder builder = new AlertDialog.Builder(this)
	    .setTitle("Rate this app")
	    .setMessage("If Call and SMS blocker helped you to block unwanted Calls or SMS, please take moment to " +
	    		"rate it. Thanks for your support.")
	    .setPositiveButton("Rate it!", null)
	    .setNegativeButton("No thanks", null)
	    .setNeutralButton("Remind me later", null);
		
		prefs = PreferenceManager.getDefaultSharedPreferences(this);
		lunchCount = prefs.getInt("count", 0) + 1;
		prefs.edit().putInt("count", lunchCount).commit();
		
		Log.d("Launches", ""+lunchCount % 3);
		if (lunchCount % 5 == 0) {
			new AppRate(this)
		    .setCustomDialog(builder)
		    //.setMinDaysUntilPrompt(7)
		    //.setMinLaunchesUntilPrompt(2)
		    .init();
		}

		prefs = PreferenceManager
				.getDefaultSharedPreferences(getApplicationContext());
		mainAct = prefs.getBoolean("startApp", true);
		eng = (Button) findViewById(R.id.englishBt);
		ur = (Button) findViewById(R.id.urduBt);

		eng.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				english = true;
				startAct();

			}
		});
		ur.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				english = false;
				startAct();
			}
		});
	}

	protected void startAct() {
		// TODO Auto-generated method stub
		Log.d("start app with lang",""+ english);
		if (mainAct) {
			i = new Intent(this, MainActivity.class);
			i.putExtra("english", english);
			startActivity(i);
		} else {
			i = new Intent(this, AlternateStart.class);
			i.putExtra("english", english);
			startActivity(i);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getSupportMenuInflater();
		inflater.inflate(R.menu.main, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.action_settings:
			Intent i = new Intent(getApplicationContext(), Preferences.class);
			startActivity(i);
			break;

		default:
			break;
		}
		return true;
	}
	 @Override
	  public void onStart() {
	    super.onStart();
	  
	    //EasyTracker.getInstance().activityStart(this); // Google Analytics.
	  }

	  @Override
	  public void onStop() {
	    super.onStop();
	    
	    //EasyTracker.getInstance().activityStop(this); // Google Analytics.
	  }

}
